# -*- coding:utf-8 -*-
# __auther__='jiangkai'

import os
from time import sleep

class ClosePrintDiag:
    def __init__(self,driver,mainHandle):
        driver.maximize_window()
        sleep(3)
        os.system(os.getcwd() + "\\openDiagPrint.exe 打印")
        sleep(2)

        all_handles = driver.window_handles

        for handle in all_handles:
            if handle != mainHandle:
                # print(driver.title+"\n"+handle)  # 输出待选择的窗口句柄
                driver.switch_to_window(handle)
                self.s1 = str(driver.find_element_by_xpath("/html/body/div/div[1]/div[2]/b[1]").text)
                self.s2 = str(driver.find_element_by_xpath("/html/body/div/div[1]/div[2]/b[2]").text)
                self.writeDangAnNO()
                sleep(2)
                try:
                    driver.close()  # 关闭当前窗口
                except Exception as e:
                    all_handles.append(handle)
                    print(e)
                    continue
        driver.switch_to_window(mainHandle)  # 返回主窗口

    def get_listno(self):
        return self.s1+self.s2

    def writeDangAnNO(self):
        wtf = open("extScript\\DangAnNO.txt", "w")
        wtf.write(self.s1+self.s2)
        wtf.close()

